<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>$Injector API</title>
<link rel="stylesheet" href="../lib/bootstrap3/css/bootstrap.min.css">
<link rel="stylesheet" href="../lib/bootstrap3/css/dashboard.css">
<script src="../lib/angularjs/angular.min.js"></script>
</head>
<body ng-app="app">
<div class="well row">
    <div ng-controller="ctrl02">
        <button class="btn-success btn" ng-click="sayHello()">点击</button>
    </div>
</div>
</body>
<script type="text/javascript">
    var app = angular.module('app', []);
    app.factory('$custom', function () {
        return {
            print: function (msg) {
                console.log(msg);
                return {msg:msg};
            }
        };
    });

    var injector = angular.injector(['app', 'ng']);
    var has = injector.has('$custom');
    console.log(has);
    if (has) {
        var custom = injector.get('$custom');
        custom.print("控制台输出任意的内容！");
    }

    ctrl02.$inject = ['$scope', '$custom'];
    app.controller('ctrl02',ctrl02);
    function ctrl02(a,b) {
        a.sayHello=function () {
            b.print('123');
        }
    }
</script>
</html>